package it.learn.kafka.consumer92;

import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;

import java.time.Duration;

public class WebClientUtil {

    public void test01() {
        WebClient webClient = WebClient.create();
        WebClient webClient1 = WebClient.create("");

        // Timeouts
        // HttpClient httpClient = HttpClient.create()
        //         .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);

        // Read and Write Timeouts
        HttpClient httpClient = HttpClient
                .create()
                .doOnConnected(conn -> conn
                        .addHandlerLast(new ReadTimeoutHandler(10))
                        .addHandlerLast(new WriteTimeoutHandler(10))
                )
                .responseTimeout(Duration.ofSeconds(2));

        WebClient webClient2 = WebClient
                .builder()
                .codecs(configurer -> {
                    configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024);
                })
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .build();

    }

}
